import os

# 基础目录
BASE_DIR = os.path.dirname(os.path.abspath(__file__))

# 训练相关目录
RUNS_DIR = os.path.join(BASE_DIR, 'runs')
DATA_DIR = os.path.join(BASE_DIR, 'data')
HISTORY_FILE = os.path.join(BASE_DIR, 'recognition_history.json')

# 模型文件
BEST_MODEL_PATH = os.path.join(RUNS_DIR, 'best_model.pth')
BEST_MODEL_JIT_PATH = os.path.join(RUNS_DIR, 'best_model_jit.pth')

# 确保必要的目录存在
def ensure_directories():
    """确保所有必要的目录都存在"""
    directories = [RUNS_DIR, DATA_DIR]
    for directory in directories:
        os.makedirs(directory, exist_ok=True)

# 获取最新的运行目录
def get_latest_run_dir():
    """获取最新的运行目录"""
    if not os.path.exists(RUNS_DIR):
        return None
    run_dirs = [d for d in os.listdir(RUNS_DIR) if d.startswith('run_')]
    if not run_dirs:
        return None
    return os.path.join(RUNS_DIR, sorted(run_dirs)[-1])

# 创建新的运行目录
def create_new_run_dir():
    """创建新的运行目录"""
    from datetime import datetime
    run_id = datetime.now().strftime('%Y%m%d_%H%M%S')
    new_dir = os.path.join(RUNS_DIR, f'run_{run_id}')
    os.makedirs(new_dir, exist_ok=True)
    return new_dir 